/**
 *
 * @author Antonio G. Zippo
 */
public class BottomUp {
    //single neuron parameters
    int branches;
    int minimum_pattern_length;
    CharSequence in[];
    int dimensionality;
        
    /* 1. Handle Inputs
     * 2. Generate the first layer
     * 3. Until in the just generated layer there is only a one node
     * 4.   Generate a new layer upon the last one
     * 
     */
    
    public BottomUp(CharSequence[] input, int br, int min, int n)
    {
        this.branches = br;
        this.minimum_pattern_length = min;
        this.in = input;
        this.dimensionality = n;
        /* 1. stima il numero di neuroni iniziali
         * 2. eventualmente fai pruning e adding
         * 3. una volta creato lo strato iniziale comincia il ciclo
         */
        /*while(isLayerNecessary(input))
        {
            makeLayer(input);
        }*/
    }
    
    public boolean isLayerNecessary(CharSequence input[])
    {
        int len = input[0].length();
        int n_nodes = len/(this.branches*this.minimum_pattern_length) + 1;
        if(n_nodes <= 1)
            return false;
        else
            return true;
    }
    
    public BULayer makeLayer(CharSequence input[])
    {
        int len = input[0].length();
        int n_nodes = len/(this.branches*this.minimum_pattern_length) + 1;
        int portion = len/n_nodes;
        BUNode nodes[] = new BUNode[n_nodes];
        
        for(int i = 0; i < n_nodes; i++)
        {
            CharSequence buffer[] = new CharSequence[this.dimensionality];
            for(int j=0; j< this.dimensionality; j++)
            {
                buffer[j] = input[j].subSequence(j*portion+1, (j+1)*portion);                
            }
            nodes[i] = new BUNode(buffer);
        }
        BULayer layer = new BULayer(n_nodes);
        return layer;
    }
    
}
